package com.dream.model.master;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.collections.CollectionUtils;
import org.hibernate.annotations.Type;

import com.dream.model.base.AppModelBase;

@Entity
@Table(name="t_mst_product")
public class Product extends AppModelBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1589637623797728803L;

	@Id
	private String id;

	@Column(name="name")
	private String name;
	
	@Column(name="category_id")
	private Long categoryId;
	
	@Column(name="repair_month")
	private Integer repairMonth = 0;
	
	@Column(name="description")
	private String description;
	
	@Column(name="deleted")
	@Type(type = "org.hibernate.type.NumericBooleanType")
	private boolean deleted = false;
	
	@Transient
	private ProductCategory firstCat;
	
	@Transient
	private ProductCategory secondCat;
	
	public void initCats(List<ProductCategory> li){
		
		if(CollectionUtils.isNotEmpty(li)){
			for(ProductCategory cat :li){
				if(cat.getLevel().equals(1)){firstCat = cat;}
				if(cat.getLevel().equals(2)){secondCat = cat;}
			}
		}
	}
	
	public ProductCategory getFirstCat() {
		return firstCat;
	}

	public void setFirstCat(ProductCategory firstCat) {
		this.firstCat = firstCat;
	}

	public ProductCategory getSecondCat() {
		return secondCat;
	}

	public void setSecondCat(ProductCategory secondCat) {
		this.secondCat = secondCat;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}


	public Integer getRepairMonth() {
		return repairMonth;
	}

	public void setRepairMonth(Integer repairMonth) {
		this.repairMonth = repairMonth;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Product other = (Product) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}
